home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MPW_TOOL
/
TOOLS
/
TOOLS_WI
/
ICON_8
/
MEMMON_F
/
MMRT.C
< prev
next >
Wrap
Text File
|
1990-03-02
|
8KB
|
267 lines
/*
* mmrt.c: graphics driver for Raster Tech One/80.
*
* This Raster Tech unit is a 1280 x 1024 x 24 color display, where
* the 8 bits of each color plane are interpreted through a lookup table.
* We use it as if it were 1280 x 1024 x 8 display, with lookup.
*/
#include <varargs.h>
#include "memmon.h"
hidden novalue rtcmd Params((/*varargs*/));
#define HSize 1280 /* horizontal screen size */
#define VSize 1024 /* vertical screen size */
#define CTAddr 0xFC00 /* color table address in raster tech */
/* raster tech command bytes and formats */
#define SGPX "\004" /* enter graphics (standard) */
#define EGPX "\005" /* enter graphics (redef from \004) */
#define BLINKC "\043"
#define BLINKE "\040bbbb"
#define BLINKR "\042b"
#define CLEAR "\207"
#define CONFIG "\044wwwwwwww"
#define DRW3R "\203bb"
#define LUT8 "\034bbbb"
#define MOVABS "\001xy"
#define PIXFUN "\073b"
#define POKE "\276ww"
#define PRMFIL "\037b"
#define QUIT "\377"
#define RECREL "\211xy"
#define RGBTRU "\116b"
#define SCRORG "\066xy"
#define SPCHAR "\262bbb"
#define TEXTN "\251bbww"
#define TEXT1 "\220b"
#define VAL8 "\206b"
#define VECPAT "\056w"
#define WINDOW "\072xyxy"
#define WMSK16 "\104w"
#define ZOOM "\064b"
static int xll, yll; /* screen coordinates of LL corner */
/*
* devsetup() - set globals to device-dependent values.
*/
novalue devsetup()
{
granularity = 2;
width = HSize;
height = VSize;
textrow = 20;
textsep = 6;
memrow = 20;
}
/*
* devinit() - initialize for graphics output.
*/
novalue devinit()
{
static char obuf[BUFSIZ]; /* small buffer for smoother output */
int xsize, ysize;
if (height > VSize) /* limit height to maximum */
height = VSize;
if (width > HSize) /* similarly for width */
width = HSize;
xll = - width / 2; /* center horizontally */
yll = (VSize / 2) - height; /* move to top of screen */
litout(); /* set literal output mode if tty line*/
setbuf(stdout, obuf); /* use small buffer -- less jerky */
putchar(0); /* try to flush incomplete commands */
putchar(0);
putchar(0);
putchar(0);
rtcmd(QUIT); /* exit graphics mode */
rtcmd(SGPX); /* enter gpx mode, if not yet redef */
rtcmd(SPCHAR, 0, 1, *EGPX); /* redefine from \04 to \05 */
rtcmd(QUIT); /* exit graphics mode */
rtcmd(EGPX); /* enter graphics mode (for sure) */
rtcmd(CONFIG, 0x2000, 0x400, 0x800, 0x1000, 0x400, 0, 0, 0);
/* configure memory */
rtcmd(RGBTRU, 1); /* use 24-bit mode */
rtcmd(ZOOM, 1); /* reset zoom */
rtcmd(SCRORG, 0, 0); /* set screen origin */
rtcmd(WINDOW, -HSize / 2, -VSize / 2, HSize / 2 - 1, VSize / 2 - 1);
/* set clipping window */
rtcmd(PRMFIL, 1); /* set filled primitives */
rtcmd(VECPAT, 0xFFFF); /* set solid lines */
rtcmd(PIXFUN, 0); /* set opaque mode */
rtcmd(WMSK16, 0xFFFF); /* enable all bit planes */
/* set text paramaters. constants were empirically determined. */
xsize = 2.6 * width / TextLength;
ysize = 1.6 * textrow;
rtcmd(TEXTN, xsize, ysize, 0, 0); /* set text parameters */
rtcmd(BLINKC); /* clear blink table */
rtcmd(BLINKR, 20); /* set blink rate (1.5 Hz) */
rtcmd(BLINKE, 7, Unmarked + C_Blink, 0, 255); /* blink black/white */
}
/*
* devmap() - load color map into device. Also write a shadow copy of the map
* in high Raster Tech memory for use by rtscreen(1).
*/
novalue devmap()
{
int i;
for (i = 0; i < MapSize; i++)
rtcmd(LUT8, i, cmap[i].red, cmap[i].green, cmap[i].blue);
for (i = 0; i < MapSize; i += 2) {
rtcmd(POKE, CTAddr + i, (cmap[i].red << 8) | cmap[i+1].red);
rtcmd(POKE, CTAddr + i + 256, (cmap[i].green << 8) | cmap[i+1].green);
rtcmd(POKE, CTAddr + i + 512, (cmap[i].blue << 8) | cmap[i+1].blue);
}
}
/*
* devflood(c) - fill screen with color c.
*/
novalue devflood(c)
int c;
{
rtcmd(VAL8, c); /* set color for clear */
rtcmd(CLEAR); /* clear screen */
}
/*
* devpaint(start, n, color, b) - paint n pixels in given color.
* If b >= 0, the last pixel is to be that color instead (for a border)
*/
novalue devpaint(s, n, c, b)
word s, n;
int c, b;
{
int x, y;
if (b >= 0) /* if border, decr total count*/
n--;
x = s % width; /* where on row, which row? */
y = memheight - memrow * (1 + s / width);
rtcmd(VAL8, c); /* set color */
while (x + n >= width) { /* draw all rows but last */
rtcmd(MOVABS, xll + x, yll + y); /* position to LL corner */
rtcmd(RECREL, width - 1 - x, memrow - 1 - 1); /* draw to UR corner */
n -= width - x; /* decr count */
x = 0; /* move to start of next row */
y -= memrow;
}
if (n) { /* last row */
rtcmd(MOVABS, xll + x, yll + y); /* position */
rtcmd(RECREL, n - 1, memrow - 1 - 1); /* draw */
x += n;
}
if (b >= 0) { /* border */
rtcmd(VAL8, b); /* color */
rtcmd(MOVABS, xll + x, yll + y); /* position */
rtcmd(DRW3R, 0, memrow - 1 - 1); /* draw */
}
}
/*
* devtext(string, row, col, fgcolr, bgcolr) - output text.
*/
novalue devtext(s, row, col, fg, bg)
char *s;
int row, col, fg, bg;
{
int x, y, n;
float charwidth;
charwidth = (float)width / (float)TextLength;
n = strlen(s);
x = col * charwidth; /* where on line? */
y = height - textrow * (row + 1) + 1; /* which line? */
rtcmd(VAL8, bg); /* set bkground color */
rtcmd(MOVABS, xll + x, yll + y); /* position */
rtcmd(RECREL, (int)(charwidth * (n + 1)) - 2, textrow - 2);
/* draw background */
if (fg == bg || n == 0) /* if no text */
return;
rtcmd(VAL8, fg); /* set text color */
rtcmd(MOVABS, xll + x + (int)(.45*charwidth), yll + y + (int)(.25*textrow));
rtcmd(TEXT1, n); /* issue text func */
while (*s)
putchar(*s++); /* send the chars */
}
/*
* devsnap() - batch mode snapshot; no action needed here.
*/
novalue devsnap()
{
}
/*
* devflush() - flush output.
*/
novalue devflush()
{
if (stdout->_cnt & 1) /* ugh! */
putchar(0); /* make byte count even */
fflush(stdout);
}
/*
* devterm() - terminate graphics
*/
novalue devterm()
{
rtcmd(SPCHAR, 0, 1, *SGPX); /* reset "enter graphics" character */
rtcmd(QUIT); /* exit graphics mode */
putchar(0); /* dma driver requires "some" nulls */
putchar(0);
putchar(0);
putchar(0);
putchar(0);
putchar(0);
devflush(); /* flush output */
}
/*
* rtcmd(s, args) - output command to raster tech.
* s is a string specifying the command format. The first character is a
* raster tech function code. Each additional character specifies the format
* for outputting one more argument (see below).
*/
/*VARARGS1*/
static novalue rtcmd(s, va_alist)
char *s;
va_dcl
{
va_list ap;
char c;
unsigned int n;
va_start(ap); /* set up varargs stuff */
putchar(*s++); /* output function byte */
while (c = *s++)
switch (c) { /* format characters are: */
case 'b': /* b - output byte */
n = va_arg(ap, unsigned int);
putchar(n);
break;
case 'w': /* w - output word */
case 'x': /* x - output x-coordinate */
case 'y': /* y - output y-coordinate */
n = va_arg(ap, unsigned int);
putchar(n >> 8);
putchar(n);
break;
}
}